package logic

import (
	"context"
	"doctor-medicine-system/models"
	"errors"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicineUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMedicineUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicineUpdateLogic {
	return &MedicineUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 修改
func (l *MedicineUpdateLogic) MedicineUpdate(in *doctorrpc.MedicineUpdateRequest) (*doctorrpc.MedicineUpdateResponse, error) {
	// todo: add your logic here and delete this line

	var doctor models.Doctor
	if err := doctor.LoginDoctor(models.DB); err != nil {
		return nil, err
	}

	var medicine models.Medicine
	if err := medicine.UpdateMedicine(models.DB); err != nil {
		return nil, errors.New("修改失败")
	}

	return &doctorrpc.MedicineUpdateResponse{
		MedicineId: int64(medicine.ID),
	}, nil
}
